package com.bowlong.net.proto;

import java.io.OutputStream;

import com.bowlong.bio3.B3OutputStream;
import com.bowlong.io.ByteOutStream;
import com.bowlong.objpool.ByteOutPool;

public class N3Support {
	// //////////////
	public static final ByteOutStream getStream() {
		ByteOutStream baos = ByteOutPool.borrowObject();
		return baos;
	}

	public static final void freeStream(final ByteOutStream os) {
		ByteOutPool.returnObject(os);
	}

	// //////////////

	public static final void writeVectorTag(final OutputStream out,
			final int len) throws Exception {
		if (out == null)
			return;
		B3OutputStream.writeListTag(out, len);
	}

	public static final void writeVectorEntry(final OutputStream out,
			final Object object) throws Exception {
		B3OutputStream.writeObject(out, object);
	}

	// //////////////

	public static final void writeMapTag(final OutputStream out, final int len)
			throws Exception {
		if (out == null)
			return;
		B3OutputStream.writeMapTag(out, len);
	}

	public static final void writeMapEntry(final OutputStream out,
			final Object key, final Object var) throws Exception {
		if (out == null || key == null)
			return;
		B3OutputStream.writeObject(out, key);
		B3OutputStream.writeObject(out, var);
	}
	// //////////////

	// public static String toStrKey(Object... a) {
	// if (a == null)
	// return "null";
	// int iMax = a.length - 1;
	// if (iMax == -1)
	// return "[]";
	//
	// StringBuilder b = new StringBuilder();
	// b.append('[');
	// for (int i = 0; ; i++) {
	// b.append(a[i]);
	// if (i == iMax)
	// return b.append(']').toString();
	// b.append(", ");
	// }
	// }
}
